class Book
// A Book object is used to handle and provide information about books customization
and production.
Attributes:
String title; // the title of the book
int pageNumber; // the number of pages in the book
float pageHeight; // the height of a page in centimeters
float pagewidth; // the width of a page in centimeters
Operations:
Book: Use Book_title, number_of_pages, page_height and page_width to
initialize the attributes of the object.
Book(String Book_title,int number_of_pages,float page_height,float page_width);
getTitle(): Return the title
String getTitle();
getCost(): Return the cost = (number of pages N X A area in cm squared)/40
double getCost();
Example:
#include <iostream>
#include "Book.h"
int main()
{
//Creating the information object
Book information("Lost in time",35,27.94,21.59);
//Calling various functions
cout<<" The book "<< information.getTitle()<<" has a cost of :$"
<<information.getCost()<<endl;
return 0;
}
Run:
The book Lost in time has a cost of :$81.8125
class Elevator
// An Elevator object is used to manipulate operations and applications done to an
elevator.
Attributes:
int peopel_in; // the number of people in the elevator
int on_floor; // the floor the elevator is on
int numFloors; // the number of floors in the building
Operations:
Elevator: Use people and floor to initialize the attributes of the object.
Elevator (int people =0,int floor=0);
addPerson: Takes the number of people to be added as an argument and updates the
number of people inside the elevator.
void addPerson(int person_in);
removPerson:Takes the number of people to be removed as an argument and updates
the total number of people inside the elevator.
void removPerson(int person_out);
moveUp: Takes the number of floors to go up and updates the position of
the elevator.
void moveUp (int floors_Up);
moveDwn: Takes the number of floors to go down and updates the position of
the elevator.
void moveDwn(int floors_Dwn);
writeReport:Give a summary of the current elevator status.
void writeReport();
Example:
#include <iostream.h>
#include "Elevator.h"
int main()
{
int person_in,person_out,floors_Up,floors_Dwn;
//creating the Friday 06,2000 object
Elevator Friday0600(5,1);
cout<<" Enter the floor to go UP to: "<<endl;
cin>>floors_Up;
//invoking the moveUp function
Friday0600.moveUp(floors_Up);
cout<<" Enter the number of people to be added in the elevator: "<<endl;
cin>> person_in;
Friday0600.addPerson(person_in);
cout<<" The current elevator information: "<<endl;
write.Report();
return 0;
}
Run:
Enter the floor to go UP to:
4
Enter the number of people to be added in the elevator:
3
The current elevator information:
Number of people inside: 8
Elevator sits on floor : 4
|